package com.unknow.first.dapp.admin.account.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.unknow.first.dapp.admin.account.constants.ITradeTypeEnum;
import com.unknow.first.dapp.admin.account.mapper.AddressAccountDetail;
import com.unknow.first.dapp.admin.account.mapper.AddressAccountInfo;
import com.unknow.first.dapp.admin.account.mapper.AddressCoinConfig;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @author Administrator
 * @description 针对表【t_address_account_info】的数据库操作Service
 * @createDate 2022-05-17 10:21:36
 */
public interface AddressAccountInfoService extends IService<AddressAccountInfo> {

    int createAddressAccount(AddressAccountInfo accountInfo) throws Exception;

    List<AddressAccountInfo> queryAccountInfoByAddress(Map<String, Object> params) throws Exception;

    /**
     * 通过detail去更新accountInfo的信息，如果没有就会创建出来，通过触发器控制balance不能小于0
     *
     * @param accountDetail
     * @return
     */
    boolean updateBalanceByAccountDetail(AddressAccountDetail accountDetail) throws Exception;
    /**
     * 资金加减，创建资金明细
     *
     * @param
     * @return 资金明细
     */
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.MANDATORY)
    AddressAccountDetail processFundAndDetail(BigDecimal amount, AddressCoinConfig coinConfig, ITradeTypeEnum tradeType,
        String remark, Long referId, String address, String admin) throws Exception;

    @Transactional(rollbackFor = Exception.class, propagation = Propagation.MANDATORY)
    AddressAccountDetail processFundAndDetail(BigDecimal amount, AddressCoinConfig coinConfig, ITradeTypeEnum tradeType,
        String remark, Long referId, String address, String admin, int status) throws Exception;



//    @Transactional(rollbackFor = Exception.class, propagation = Propagation.MANDATORY)
//    AddressAccountDetail processFundAndDetail(BigDecimal amount, AddressCoinConfig coinConfig, Integer tradeType, String tradeTypeI18nValue,
//        String remark, Long referId, String address, String admin, int status) throws Exception;
//
//    @Transactional(rollbackFor = Exception.class, propagation = Propagation.MANDATORY)
//    AddressAccountDetail processFundAndDetail(BigDecimal amount, AddressCoinConfig coinConfig, Integer tradeType, String tradeTypeI18nValue,
//        String remark, Long referId, String address, String admin) throws Exception;

    /**
     * 创建账户
     *
     * @param address
     * @return
     */
    public void createAddressAccount(String address);

    public AddressAccountInfo getAddressAccountByCoinId(String address, Integer coinId);

    /**
     * 更新账户状态
     *
     * @param id
     * @param status
     * @return
     */
    int updateStatusById(Long id, Integer status);
}
